/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package arbitration.gui;

import arbitration.logic.validator.CountValidator;
import arbitration.logic.formatter.PriceFormatter;
import arbitration.logic.validator.PriceValidator;
import com.toedter.calendar.JDateChooser;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author prophet
 */
public class CalcPanel extends JPanel{
    private JTextFieldValidator principalDebt;
    private JLabel lPrincipalDebt;
    private JDateChooser deliveryDate;
    private JLabel lDeliveryDate;
    private JComboBox currencyDebt;
    private JTextFieldValidator paymentDays;
    private JLabel lDatePayment;
    private JTextField paymentPeriod;
    private JLabel lPaymentPeriod;
    private JLabel lDays;
    private JLabel lEndDateDelay;
    private JDateChooser endDateDelay;
    private JLabel lOtherExpenses;
    private JTextFieldValidator otherExpenses;
    private JComboBox currencyExpenses;
    private DefaultTableModel dtm;
    private JTable table;
    private JLabel lArbitrationFee;
    private JTextField arbitrationFee;    
    private JLabel lTotal;
    private JTextField total;
    private JDateChooser decisionDate;
    private JLabel lDecisionDate;
    private JButton calc;

    private CountValidator countValidator;
    private PriceValidator priceValidator;

    public CalcPanel(){
        this.setLayout(new GridBagLayout());
        int y=0;
        JPanel inputPanel=new JPanel();
        inputPanel.setLayout(new GridBagLayout());

        countValidator=new CountValidator();
        priceValidator=new PriceValidator();

        lPrincipalDebt=new JLabel("Сумма основного долга:");
        lPrincipalDebt.setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        inputPanel.add(lPrincipalDebt, new GridBagConstraints(0, y, 1, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(10, 0, 10, 10), 0, 0));
        principalDebt=new JTextFieldValidator(priceValidator, new PriceFormatter());
        principalDebt.setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));        
        inputPanel.add(principalDebt, new GridBagConstraints(1, y, 1, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(10, 10, 10, 10), 0, 0));
        currencyDebt=new JComboBox();
        currencyDebt.setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        currencyDebt.addItem("BYR");
        currencyDebt.addItem("RUR");
        currencyDebt.addItem("USD");
        inputPanel.add(currencyDebt, new GridBagConstraints(2, y++, 1, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(10, 0, 10, 10), 5, 0));

        lDeliveryDate=new JLabel("Дата поставки:");
        lDeliveryDate.setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        inputPanel.add(lDeliveryDate, new GridBagConstraints(0, y, 1, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 0, 10, 10), 0, 0));
        deliveryDate=new JDateChooser();
        deliveryDate.setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        inputPanel.add(deliveryDate, new GridBagConstraints(1, y++, 1, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 10, 10, 10), 0, 0));

        lDatePayment=new JLabel("Срок оплаты:");
        lDatePayment.setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        inputPanel.add(lDatePayment, new GridBagConstraints(0, y, 1, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 0, 10, 10), 0, 0));
        paymentDays=new JTextFieldValidator(countValidator,null);
        paymentDays.setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        inputPanel.add(paymentDays, new GridBagConstraints(1, y, 1, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 10, 10, 10), 0, 0));
        lDays=new JLabel(" день/дней");
        lDays.setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        inputPanel.add(lDays, new GridBagConstraints(2, y++, 1, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 0, 10, 10), 0, 0));

        lPaymentPeriod=new JLabel("Период для оплаты:");
        lPaymentPeriod.setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        inputPanel.add(lPaymentPeriod, new GridBagConstraints(0, y, 1, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 0, 10, 10), 0, 0));
        paymentPeriod=new JTextField("заполните необходимые поля");
        paymentPeriod.setEditable(false);
        paymentPeriod.setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        paymentPeriod.setForeground(Color.gray);
        inputPanel.add(paymentPeriod, new GridBagConstraints(1, y++, 1, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 10, 10, 10), 0, 0));

        lEndDateDelay=new JLabel("Дата окончания просрочки:");
        lEndDateDelay.setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        inputPanel.add(lEndDateDelay, new GridBagConstraints(0, y, 1, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 0, 10, 10), 0, 0));
        endDateDelay=new JDateChooser();
        endDateDelay.setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        inputPanel.add(endDateDelay, new GridBagConstraints(1, y++, 1, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 10, 10, 10), 0, 0));

        lOtherExpenses=new JLabel("Иные расходы:");
        lOtherExpenses.setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        inputPanel.add(lOtherExpenses, new GridBagConstraints(0, y, 1, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 0, 10, 10), 0, 0));
        otherExpenses=new JTextFieldValidator(priceValidator,new PriceFormatter());
        otherExpenses.setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        inputPanel.add(otherExpenses, new GridBagConstraints(1, y, 1, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 10, 10, 10), 155, 0));
        currencyExpenses=new JComboBox();
        currencyExpenses.setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        currencyExpenses.addItem("BYR");
        currencyExpenses.addItem("RUR");
        currencyExpenses.addItem("USD");
        inputPanel.add(currencyExpenses, new GridBagConstraints(2, y++, 1, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 0, 10, 10), 0, 0));

        lDecisionDate=new JLabel("Дата вынесения решения:");
        lDecisionDate.setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        inputPanel.add(lDecisionDate, new GridBagConstraints(0, y, 1, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 0, 10, 10), 0, 0));
        decisionDate=new JDateChooser();
        decisionDate.setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        inputPanel.add(decisionDate, new GridBagConstraints(1, y, 1, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 10, 10, 10), 0, 0));

        add(inputPanel, new GridBagConstraints(0, 0, 5, 1, 0, 0, GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE, new Insets(10, 10, 0, 10), 0, 0));

        JPanel buttonsPanel=new JPanel();
        buttonsPanel.setLayout(new GridBagLayout());        
        JButton add=new JButton("Добавить");
        add.setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        buttonsPanel.add(add, new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
        JButton change=new JButton("Изменить");
        change.setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        buttonsPanel.add(change, new GridBagConstraints(1, 1, 1, 1, 0, 0, GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
        JButton delete=new JButton("Удалить");
        delete.setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        buttonsPanel.add(delete, new GridBagConstraints(2, 1, 1, 1, 0, 0, GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE, new Insets(0, 0, 5, 0), 0, 0));

        add(buttonsPanel, new GridBagConstraints(0, 1, 3, 1, 0, 0, GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE, new Insets(5, 10, 0, 0), 0, 0));

        dtm = new DefaultTableModel();
        dtm.addColumn("Дата погашения");
        dtm.addColumn("Сумма погашения");
        dtm.addColumn("Остаток долга");
        dtm.addColumn("Срок задолжности");
        dtm.addColumn("Пеня");
        dtm.addColumn("Сумма пени");
        dtm.addColumn("Проценты");
        dtm.addColumn("Сумма процентов");
        dtm.addColumn("Ставка");
        dtm.addRow(new String[]{"15.12.2010","10 000 000 BYR","49 101 100 BYR","27 день/дней","270 000 BYR","270 000 BYR", "77 671 BYR","77 671 BYR","10.5"});
        dtm.addRow(new String[]{"15.12.2010","10 000 000 BYR","49 101 100 BYR","27 день/дней","270 000 BYR","270 000 BYR", "77 671 BYR","77 671 BYR","10.5"});
        dtm.addRow(new String[]{"15.12.2010","10 000 000 BYR","49 101 100 BYR","27 день/дней","270 000 BYR","270 000 BYR", "77 671 BYR","77 671 BYR","10.5"});
        table = new JTable(dtm){
            @Override
            public boolean isCellEditable ( int row, int column )
            {
                return false;
            }
        };
        table.getColumn("Ставка").setMaxWidth(50);
        table.setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        table.getTableHeader().setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        table.setShowHorizontalLines(false);
        table.setSelectionBackground(Color.black);
        table.setSelectionForeground(Color.white);        
        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

        add(new JScrollPane(table), new GridBagConstraints(0, 2, 10, 1, 1, 1, GridBagConstraints.NORTH,
            GridBagConstraints.BOTH, new Insets(0, 10, 10, 10), 0, 0));

        calc=new JButton("Расчет");
        calc.setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        add(calc, new GridBagConstraints(0, 3, 1, 1, 0, 0, GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE, new Insets(0, 10, 5, 5), 0, 0));

        lArbitrationFee=new JLabel("Арбитражный сбор:");
        lArbitrationFee.setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        add(lArbitrationFee, new GridBagConstraints(0, 4, 1, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 10, 10, 10), 0, 0));
        arbitrationFee=new JTextField(20);
        arbitrationFee.setEditable(false);
        arbitrationFee.setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        add(arbitrationFee, new GridBagConstraints(1, 4, 1, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 10, 10, 10), 130, 0));       

        lTotal=new JLabel("Итого подлежит взысканию:");
        lTotal.setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        add(lTotal, new GridBagConstraints(0, 5, 1, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 10, 10, 10), 0, 0));
        total=new JTextField(20);
        total.setEditable(false);
        total.setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        add(total, new GridBagConstraints(1, 5, 1, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 10, 10, 10), 130, 0));
    }

    public JTextFieldValidator getPaymentDays() {
        return paymentDays;
    }

    public JDateChooser getDeliveryDate() {
        return deliveryDate;
    }

    public JTextField getPaymentPeriod() {
        return paymentPeriod;
    }

    public JButton getCalc() {
        return calc;
    }

    
}
